﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HeerCards.Info;
using LitJson;
using PropertyChanged;
namespace github.heerheer.card2.UI.ViewModels
{
    [AddINotifyPropertyChangedInterface]
    public class SettingsViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public GobalSetting GlobalSetting { get; set; }

        public ObservableCollection<RewardInfo> CheckinRewards { get => new ObservableCollection<RewardInfo>(GlobalSetting.CheckinRewards); set => GlobalSetting.CheckinRewards = new List<RewardInfo>( value); }

        public SettingsViewModel()
        {
            GlobalSetting = new GobalSetting();
        }
        public void LoadConfig(string Path)
        {
            if (!File.Exists(Path)) {
                File.Create(Path);
                //空文件将无法序列化所以new一个
                GlobalSetting = new GobalSetting();
                return;
            }
            if (File.ReadAllText(Path) == "")
            {
                File.WriteAllText(Path,JsonMapper.ToJson(new GobalSetting()));
            }
            GlobalSetting = JsonMapper.ToObject<GobalSetting>(File.ReadAllText(Path));
        }
    }
}
